package com.msmall.community.vote.action.html;

import java.util.Date;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantAjax;
import com.msmall.base.util.ConstantDB;
import com.msmall.community.vote.model.Vote;
import com.msmall.community.vote.service.VoteManager;

public class TravelAction extends HTMLBaseAction{

	private static final long serialVersionUID = 3083619354588948976L;

	private VoteManager voteManager;

	private Long voted;
	
	public String voteTravel(){
		StringBuffer buffer = new StringBuffer();
		try {
			buffer.append(ConstantAjax.RETURN_PRE);
			Vote vote = new Vote();
			vote.setCreateTime(new Date());
			vote.setModule(ConstantDB.VOTE_MODULE_TRAVEL);
			vote.setTypes(ConstantDB.VOTE_TYPES_POSITIVE);
			vote.setVoted(voted);
			vote.setVoter(getUserid());
			voteManager.addVote(vote, getUserid());
			int total = voteManager.loadTotalVote(voted, ConstantDB.VOTE_MODULE_TRAVEL, ConstantDB.VOTE_TYPES_POSITIVE);
			buffer.append(createResult("true"));
			buffer.append(createEasyContent(String.valueOf(total)));
		} catch (Exception e) {
			buffer.append(createResult("false"));
			log.error(e.getStackTrace());
		}
		buffer.append(ConstantAjax.RETURN_SUFF);
		message = buffer.toString();
		return SUCCESS;
	}
	
	public Long getVoted() {
		return voted;
	}

	public void setVoted(Long voted) {
		this.voted = voted;
	}

	public void setVoteManager(VoteManager voteManager) {
		this.voteManager = voteManager;
	}
}
